<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/12
 * Time: 11:17
 */

namespace app\api\model;


use think\Model;

class CountryDegreeMajor extends Model
{

    /**
     * @param $type
     * @param $pid
     * @param $country_ids
     * @param $degree_ids
     * @param $major_ids
     * 存国家学位专业关联
     */
    public function add($type,$pid,$country_ids,$degree_ids,$major_ids){
        foreach ($country_ids as $k=>$v){
            foreach ($degree_ids as $key=>$valve){
                foreach ($major_ids as $a=>$c){
                    $addData = array(
                        'type'=>$type,
                        'pid'=>$pid,
                        'content'=>$v.'#'.$valve.'#'.$c,
                    );
                    $this->insertGetId($addData);
                }
            }
        }
    }

    /**
     * @param $type
     * @param $pid
     * @param $country_ids
     * @param $degree_ids
     * @param $major_ids
     * 修改国家学位专业关联
     */
    public function edit($type,$pid,$country_ids,$degree_ids,$major_ids){
        $this->where(array('pid'=>$pid,'type'=>$type))->delete();
        foreach ($country_ids as $k=>$v){
            foreach ($degree_ids as $key=>$valve){
                foreach ($major_ids as $a=>$c){
                    $addData = array(
                        'type'=>$type,
                        'pid'=>$pid,
                        'content'=>$v.'#'.$valve.'#'.$c,
                    );
                    $this->insertGetId($addData);
                }
            }
        }
    }
}